package com.downrice.security;

import com.downrice.dao.UserRepository;
import com.downrice.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Created by lxiafan on 2017/1/10.
 */
public class customUserService implements UserDetailsService{
    @Autowired
    UserRepository ur;
    @Override
    public UserDetails loadUserByUsername(String username){
        System.out.println(username+"23333333333");
        User u = ur.findByUsername(username);
        if(u == null){
            System.out.println("用户名不存在");
            throw new UsernameNotFoundException("用户名不存在");
        }
        return u;
    }
}
